package com.huangj.pro2_h2pop;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.widget.TextView;

import com.huangj.entity.TravelEntity;
import com.huangj.fragments.TravPicSeeFragment;
import com.huangj.huangjlibrary.base.BaseActivity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by HuangJ on 2016/10/6.19:17
 */
public class TravelPicsActivity extends BaseActivity{

    private List<TravelEntity.ActivityBean.ContentsBean> pics;
    private  TravPicAdapter travPicAdapter;
    @BindView(R.id.travel_vp)
    ViewPager viewPager;
    @BindView(R.id.tr_tv1)
    TextView tv1;
    @BindView(R.id.tr_tv2)
    TextView tv2;
    @Override
    protected int getContentId() {
        return R.layout.travelpic_layout;
    }

    @Override
    protected void init() {
        Intent intent = getIntent();
        pics = (List<TravelEntity.ActivityBean.ContentsBean>) intent.getSerializableExtra("pics");
        int index = intent.getIntExtra("index",0);
        tv1.setText(pics.size()+"");
        for (int i = 0; i < pics.size(); i++) {
            Log.d("print", "传过来的图片集合："+pics.get(i).getPhoto_url());
        }

        travPicAdapter = new TravPicAdapter(getSupportFragmentManager(),pics);
        viewPager.setAdapter(travPicAdapter);
        viewPager.setCurrentItem(index);
    }

    public class TravPicAdapter extends FragmentStatePagerAdapter{
        private List<TravelEntity.ActivityBean.ContentsBean> pics;

        public TravPicAdapter(FragmentManager fm, List<TravelEntity.ActivityBean.ContentsBean> pics) {
            super(fm);
            this.pics = pics;
        }

        @Override
        public Fragment getItem(int position) {
            tv1.setText(position+1+"");
            Log.d("print", "传进Fragment的图片: "+pics.get(position).getPhoto_url());
            return TravPicSeeFragment.getIntence(pics.get(position).getPhoto_url());
        }

        @Override
        public int getCount() {
            return pics.size();
        }
    }

    @Override
    protected void onDestroy() {
        viewPager.removeAllViews();
        super.onDestroy();
    }
}
